package main

import (
	"fmt"
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
	"strconv"
	"time"
)

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("身高体重智能计算器")

	nameEntry := widget.NewEntry()
	nameEntry.SetPlaceHolder("请输入您的姓名")

	weightEntry := widget.NewEntry()
	weightEntry.SetPlaceHolder("请输入您的体重(kg)")

	heightEntry := widget.NewEntry()
	heightEntry.SetPlaceHolder("请输入您的身高 (m)")

	resultLabel := widget.NewLabel("")
	progressBar := widget.NewProgressBar()
	calculateButton := widget.NewButton("Calculate", func() {
		// 设置进度条可见
		progressBar.Show()
		resultLabel.SetText("Calculating...")

		go func() {
			time.Sleep(2 * time.Second) // 2秒延迟

			name := nameEntry.Text
			height, _ := strconv.ParseFloat(heightEntry.Text, 64)
			weight, _ := strconv.ParseFloat(weightEntry.Text, 64)
			//bmi := calculateBMI(weight, height)
			//category := getBMICategory(bmi)
			// 更新 UI
			myWindow.RequestFocus()
			resultLabel.SetText(fmt.Sprintf("%s，您的体重为%.0f斤，身高为%.0f厘米。非常优秀，请继续保持。 ", name, weight*2, height*100))
			progressBar.Hide()
		}()
	})

	content := container.NewVBox(
		nameEntry,
		weightEntry,
		heightEntry,
		calculateButton,
		resultLabel,
	)

	myWindow.SetContent(content)
	myWindow.Resize(fyne.NewSize(400, 200))
	myWindow.ShowAndRun()
}
